/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Button, TextArea,Text, useToast,
} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, useItemInputControl
} from "../../common/base";
import {管道级别} from "../../../device/edit/压力管道";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {itemA单特性} from "../EditorFeature";
// import {itemA单特性} from "../../industrial/EditorFeature";
import {itemA下结论} from "../../gas/editorJj";
import {itemA现场施工} from "../../gas/editorOnsite";
import {itemA质保体} from "../../gas/QualityAssure";
import {config证书概要, 设备排除} from "../../gas/editorCert";
import {render施工类别} from "./editCert";
import {itemA无损资格, itemA焊接资格} from "../editorOQuaf";
import {itemA工作内容} from "./editJobr";
import {itemA问题处} from "./editProb";


// export const 施工类别选=['安装','重大修理','改造'];
// export const transBsType =(type: BusinessCat_Enum)=>'INSTA'===type? '安装': 'arsk2'

//【管道特殊】 同一时间对一个设备允许出现多个监检报告的，若是台账的字段估计不能通用的。
export const config设备概况 = [
    [['工程名称', {n:'工程名称',t:'B',l:[]}], ],
    [['工程地址', {n:'工程地址',t:'B' }] ],
    [['工程总长度',{n:'总长度', u:'m'}], ['管道级别', {n:'管道级别',t:'l',l:管道级别}] ],
    [['设计压力',{n:'设压力', u:'MPa'}], ['输送介质', {n:'输介质',t:'l',l:['天然气',]}] ],
    [['开工时间',{n:'开工时',t:'d'}], ['竣工时间',{n:'竣工时',t:'d'}] ],
    [['建设单位','_$使用单位']],
    [['设计单位','设单位'], ['许可证编号','设许号']],
    [['施工单位','施单位'], ['许可证编号','施许号']],
    [['检测机构','测机构'], ['核准证编号','检证号']],
    // [['施工类别', {n:'施工类别',t:'l',l:施工类别选}], [' ',{r:''}] ],
    [['施工类别', {}, render施工类别], ['监督检验受理文号','监受理号'] ],
    // [['施工类别', {n:'施工类别',t:'l',l:施工类别选}], ['监督检验受理文号','监受理号'] ],
    //【公用的 都有结论编辑】 监督检验开始日期 ，监督检验结束日期
];

/**开启编制时的：默认值初始化操作。  若打印：本编辑器全部都不显示。
 * */
export const EntranceSetup =
React.forwardRef((
    {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
) => {
    const atPrint = useMedia('print');
    const toast = useToast();
    const doCheckNames = React.useCallback((verId: string) => {
        //config证书概要 有冲突交叉的情形：【设备排除】取代不重复的，然后 config设备概况 就省略；
        const result = assertNamesUnique([{value: rep?.tzFields},
            {value: config证书概要, type:'esnt'},
            {value: 设备排除, type:'esnt'},
            {value:[...itemA下结论,  ...itemA现场施工,...itemA焊接资格,...itemA无损资格,
                    ...itemA工作内容, ...itemA问题处,  ...itemA质保体, ...itemA单特性, ]},
            {value:['Projects', ]} ]);
        toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
    }, [rep,toast]);
    const {storage, setStorage} =React.useContext(EditStorageContext) as any;
    const getInpFilter = React.useCallback((par: any) => {
        const {_tblFixed, } =par||{};
        return {_tblFixed, };
    }, []);
    const {inp, setInp} = useItemInputControl({ref});
    if (atPrint) return null;
    else return (
        <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                             alone={alone} label={'初始化本报告，默认值配置等'}>
            {process.env.REACT_APP_TEST==='true' && <><div>
                <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                <Text variant="h5">设置待测试表格的各列宽度：</Text>
                <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                              JSON.parse(e.currentTarget.value??'[]');
                              setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
            </div>
            </>
            }
            <hr/>
        </InspectRecordLayout>
    );
});


